package cn.tedu.jdbc;

import cn.tedu.jdbc.utils.DbUtils;

import java.sql.*;

public class JDBCTest09 {
    public static void main(String[] args) {
        Connection conn = null;
        Statement stmt = null;
        ResultSet rs = null;

        try {
            conn = DbUtils.getConnection();
            stmt = conn.createStatement();
            System.out.println("Statement=" + stmt);
            String sql = "insert into t_product(name,price,create_time) values('小米su7urtul',1.0,'2025-05-27')";
            int count = stmt.executeUpdate(sql, Statement.RETURN_GENERATED_KEYS);
            System.out.println("插入了" + count + "条记录");
            rs = stmt.getGeneratedKeys();
            if (rs.next()){
                Long id = rs.getLong(1);
                System.out.println("新增行的主键值为" + id);
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        } finally {
            DbUtils.close(conn, stmt, rs);
        }
    }
}
